# coding=utf8
__author__ = 'lijian'
import config

_char_path = "/etc/ppp/gprs-connect-chat"


def get_current():
    file = open(_char_path, "r")
    lines = file.readlines()
    at = lines[10]
    apn = at.split(",")[2]
    apn = apn.replace("\n", "")[1:-1]
    file.close()

    return apn


def gen_file(apn,current):
    file = open(_char_path, "r")
    lines = file.readlines()
    file.close()

    text = ""
    for line in lines:
        text += line

    text=text.replace(current,apn)

    file = open(_char_path, "w")
    file.write(text)
    file.close()





if __name__ == '__main__':
    config.readConfig()
    apn = config.network["gprs"]["apn"]

    current = get_current()

    if current != apn:
        gen_file(apn,current)
